#! /usr/bin/env node

const commaner = require('commander');

const inquirer = require("inquirer");

// const superagent = require('superagent');

const {version} = require('./package.json');

// const promptList = [{
//     type: 'input',
//     message: '设置一个用户名:',
//     name: 'name'
// },{
//     type: "password", // 密码为密文输入
//     message: "请输入密码：",
//     name: "pwd"
// }]


const promptList = [{
    type: 'input',
    message: '设置翻译的内容:',
    name: 'q'
}]

commaner
    .version(version)
    .command('login')  //命令
    .action(() => { //动作
        // console.log("登录")
        //交互
        // inquirer.prompt(promptList).then(answers => {
        //     console.log(answers); // 返回的结果
        //     // let user = {username:'zs',password:'123'};
        //     // if(answers.name === user.username && answers.pwd === user.password){
        //     //     console.log("登录")
        //     // }

        //     superagent
        //         .get('http://fanyi.youdao.com/openapi.do?keyfrom=toaijf&key=868480929&type=data&doctype=json&version=1.1')
        //         .query({ q:answers.q}) // query string
        //         .end((err, res) => {
        //             // Do something
        //             console.log(res.body.translation);
        //         });
        // })

        setInterval(() => {
            console.log("===")
            var blessed = require('blessed')
                , contrib = require('blessed-contrib')
                , screen = blessed.screen()
                , line = contrib.line(
                    { style:
                    { line: "yellow"
                    , text: "green"
                    , baseline: "black"}
                    , xLabelPadding: 3
                    , xPadding: 5
                    , label: 'Title'})
                , data = {
                    x: ['t1', 't2', 't3', 't4'],
                    y: [6, 1, 7, 4]
                }
            screen.append(line) //must append before setting data
            line.setData([data])
            
            screen.key(['escape', 'q', 'C-c'], function(ch, key) {
                return process.exit(0);
            });

            screen.render()
            
        },1000)

        
    }) //动作

commaner.parse(process.argv)